Updated comments, structure and functions.
Fixed some bugs.