added nil check to prevent error