Minor refactorings
Added documentation and license, and some minor function renaming.