added defensive null result checks