final commit - algorithm is wrong