Code cleaned and optimized