Correcting NullPointerException at the beginning