Fixed bug that caused NullPointerException