code that works for the contest (barely)