added optional dependencies function and tweaked things accordingly