few fixes and debug outputs