add some basic documentation and refactor code