Fixed #7 with some additional NPE protection