Bug fix, working on more comprehensive tests