Improvements to the code