Heavy correction, refactoring and extension of the template. Still incomplete.