some cleanup + some debug code