fixing ridiculous code i wrote last year - note to self, never do this when you are tired and on service