General code fixes/cleanup