clone and modify from dea.googlecode.com