refactored code and fixed action bar title so that it updates its text