finished up fixing bugs and refactoring