Main Algorithm

update