Added debugging mode and unit tests