fix profiling problem that arises when theta gets reset at the end of optwrap