Some fixes to the code to make it neater