Fixing a bug in profiler function