Began refactoring. Fixed bug.