Tests, bug fixes