Adding Modal algorithm