Add documentation and bug fixes