Re-organize the code