Some fixes to code