Bug fix and test