much code tidying