Fixed NPE-causing bug