Bug fix, tests