add test and some fixes

fuuuh! I'm tired, so come down...