Added a if(object != null) check to fix nullpointer exception