improve optional dependencies function, remove duplication