<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def unget_service(self, bundle, reference, service=None):
 # type: (Any, ServiceReference, Any) -> bool """ Removes the usage of a service by a bundle :param bundle: The bundle that used the service :param reference: A service reference :param service: Service instance (for Prototype Service Factories) :return: True if the bundle usage has been removed """

        with self.__svc_lock:
            if reference.is_prototype():
                return self.__unget_service_from_factory(
                    bundle, reference, service
                )
            elif reference.is_factory():
                return self.__unget_service_from_factory(bundle, reference)

            try:
                # Remove the service reference from the bundle
                imports = self.__bundle_imports[bundle]
                if not imports[reference].dec():
                    # No more reference to it
                    del imports[reference]
            except KeyError:
                # Unknown reference
                return False
            else:
                # Clean up
                if not imports:
                    del self.__bundle_imports[bundle]

                # Update the service reference
                reference.unused_by(bundle)
                return True