cleaned up and refactored again