Fixed NullPointerException detailed on https://gist.github.com/2e2f7be6aad8f31f7b9d
Added even more NPE checks