rewrote lf and sf to be simpler, added rs