Bug fixes, tests