I've added some comments to the code and improved things... honestly.