Sort layers correctly