Added in some debug code and some basic code clean