this needs a documentation header. What does it do, what is it for, what are the inputs?