try this: http://pastie.org/1317836