minor code cleanup + added profiling code