almost finished algorithm1