Ugly code so far, but getting better...