Cleanup, refactor, more testing