clean and add profiling code