Calculate foremost layer correctly (previous implementation didn't work at all)