Minor code cleanup, more testcases added