Update spec tests, fix bugs in library