Cleanup code
Add coverage and refactor