finished algorithm part