less hacky implementation