Refactorings for better reeadability. Fixed also an error in enum name generation.
Added some comments.