moved dependency checking around a bit and corrected a possible failure
point