Starting to cleanup code and add debug code.