Refactors code.
Fixes bug of greedy snake.