added cancel of activity, also refactored some code