tidying up the code
removing duplicated code