simplify some code, add some unit tests