Improved doit script, but still not perfect