refactored code and added code for story 2