refactored maze class to encapsulate logic