General code improvements