cleanups and more test cases on functional code