cal project algorithm not working properly