finished refactoring/debugging, just adding comments now