bug fix and profiling