fixed some logical errors regarding initialization order