corrected problem 003  algorithm
minor modifications