commenting and tidying up code