Fixed some small bugs, refactoring and adding comments/documentation.