Code cleaned and structured