Add more exhaustive tests, fix remaining bugs, improve doc (#176)