Some improvements in the code