added nil check and removed some log messages