some null checks and more tests