Commented code and fixed bugs