beginning of code tidying