Some refactoring and improvements: added generic types, removed unnecessary comments, evict "new Integer"
Fixing encoding, fix some metrics