Bug fix, plus corrected tests