finished refactoring. could probably use a couple more classes somewhere though