refactoring snakeEngine