First draft of these functions. Not working properly yet, I think.