UPDATED refactored some of the code.