bug fixes and additional debugging