Almost completed initialization function