_main returns 0, not None, on success
reorganizations and some simple functional tests