modified sequential algo