refactored and cleaned up some messes