SA improved

recalculated derivatives and added a counter so the program will end
when stuck in a loop