refactor some initialize code