(of course you'll probably need to adjust, I haven't tested this code ;) )