uint_8 optimization, general refactoring plus comments