Added more functions, moved some into class definitions