algorithm seems a bit off