so ugly code but works