Re-organize code