#409 - Remove duplicate and unused code, extract constants, add doc