Documentation, refactoring

. Documented all functions
. Renamed some variables