imporved code