First attempt to general code cleanup/refactor
and using more refined approaches