An Algorithm for Belief Revision