Ported over some code cleanup