Various code cleanup