Added tests and made some functions private that should have been private