initialization and fix up. Working version