Check for nil before type asserting in another place