refactored a lot...