fixed some null pointer exceptions

partially fixes #7 
fixes #4