Cleanup, refactor, add docs