Much code cleanup and reduction