re-organize code