Refactored code and it's working!