reorganized constructor code