Major debug and clean up