major code cleanup and update