A bunch of functions that I copied from some of my other projects