fix up and optimize activity manager