hopefully staged things properly, but got some subtle changes from an intended branch as a result
working code with floats for efficiency