Refactored code- things work