Commented the code. This is the final version.