Checked code, retested and added comments where necessary