Document code so far and refactor