re-organize code structure