General improvements to the code