Fix layer traversing
This fixes two bugs:
- A crash when moving an object away from the root layer
- An inconsistency when going through the layers with {ctrl,shift}-Pg{Up,Down}: Going to the previous layer worked fine while going to the next layer only went up the hierarchy but never into sub layers. Now both directions visit the same layers in the same (just reversed) order.