Fixes #331

Also updated existing test cases and resolved some issues with these tests.

Please consider the Dec 08, 2014 commit only when merging, thanks!