More tests, fix minor bugs, API cleanup