Probably fixed possible NPE. Needs more testing. closes #13