refactored a lot of stuff