fixing initialization bugs and add share debug code