Changed function to support any base.