Fixed NullPointerException

closes #363