Completed refactoring code. Final version being pushed