Bug fix with more tests
More consistent API