Fix bugs in fitness and pixel distance functions