Tried to write clean and shorten code. Possible scoping issues with getData.