Refactored init code.