Refactored code 10:14am working version