refactored and cleaned up some poor design