Bug fixes, updated tests