Fixed documentation and refatoring.