Added tests and debug messages