this looks ugly, but i dont' know of a better way to do it