Fixed NPE and timing issue