This code was moved as-is from another place. Please improve it at you see fit.