Functions commented and fixed small bugs.