Updated handling for optional dependencies and added test case