is there a better way to do this?
also, this could be turned into a lib