First draft of functions for manuscript