General code refactoring/improvements.