Misc fixes and refactoring for activity