somewhat awkward functional impl