General code fixes