Fixed some nullpointer and did quite some testing.