moved check to see if it helps prevent exceptions