fixed some nullpointer and added tests