Refactoring + begun unit tests