Updated algorithm, formatting