Bug fix and tests
Minor adjustments