got the alrogithm to work