major tidying up to make more readable