completely refactored