Rewritten init function.