refactored code to only GET data when necessary