straightened up the metropolis function