Fixed one important bug, and a few test bugs