some fixes, write tests