this is ugly but it gets the job done.