awful code but works