made setpoint calculation easier to read.
Buffered input & output & simplified some file read functions to increase performance (performance tested)