Some docs, formatting and refactor