Code clean up, reorder functions logically.