[CLNUP] replace arrays with intmap
[CLNUP] a bit of refactoring