Adding gradient tests, many more comments in propagation_distance_field.h, and doing a bit of refactoring