Added check for key nil