[1.8.x] + refactored the code to look more like [master]