Final fixes on the code, added comments and stuff