refactored pretty much everything