snake implementation