Small code fixes and reestructuration.