Added key code comments
Simplified functions
Cached direction check