Fix NullPointerException and add some test cases


Fixes #76 
This is now redundant :)