Refactor initialize code