reorganized and added check for init