An improved algorithm for reducing reflectometry data involving divergent beams or non-flat samples