some improvements in the code