Fixed some bad practises and added a few comments