Improves code suggested by @gabrielpjordao