Large code cleanup part 2