add test and better logging