Rearranged code to check for None _before_ trying to read.