Code re-factoring and cleanup.