Attept at simulated annealing, not working and hideously inelegant