Fixed potential issues in snake.js