some tweaks and better unit test