Heavy correction, refactory and extension. Still incomplete.