Much necessary code cleanup