bunch of improvements and refactoring. going to need to test now