Poor code, but it works.