added try-catch to stop null pointer exceptions