Fix bug 516; include some bug testcases.