Fix NullPointerException on opening files