hw3 bug fixes and refactoring