improved snake code structure