cleaned up and refactored some stuff