additional debug code and balance logic