almost everything refactored