General code improvments