Added coments to functions and '_'s to marks stuff as private where needed