Pure bash version, faster