code cleanup, add profiling option