Fixed NPE

Closes #635