refactored a bunch