removed code duplicates and add additional checks if the needed modules are installed