moved check for data being null to top of function, partially for clarity, and partially in case a line referencing data is placed above it during coding