MAJOR BUX FIX and cleaned up some code