Fix bugs and refactor activity controller