Final code submission - lots of refactoring & functionality checks