modifications and tweaks following @reyesr contribution