Adding in some testcases and some bug fixes.