minor changes and tidying up code