Refactored activity code