sandbox algorithm reformuled