Fixed NullPointerException. But someone should check if the solution is
correct please.