Better algorithm for up/down/left/right