tidying of function