Added tests and some debug functions.