Code clean-up and reorder