correct algorithm implemented
code implementation corrected