refactored a bunch of stuff