improved profiling code