Various functions and minor bug fixes

There's no real theme here, apart from these being functions that looked easy to implement, or were needed for something else I wanted to implement.