Added catch for the nullpointerexception