Tested and tweaked.