fix #5

optimize with search method, added null checker and tests