added better dependency inversion code