algorithm is working now