refs #1061, fix some bugs and a test