added catch for NullPointerException, it exits function