removed some debug code and added some handling code