updated gist to refactored code