Grudgingly hacked together byDave Birss