Tests, improvements, bug fixes