code cleaned and organised