Re-factor code.

Code changes,