improvement: declaration of types with LOCALLY

submitted again, more modularized, clearer and  easier to merge
added some documentations