last hitting code, removal of some unneeded functions, removal of some debug code