updated with correct algorithm

updated with correct algorithm