Few fixes and some debug logging