Polished the design, implemented claus' comments and minor changes.