code cleanup - broke up large functions