Many bug fixes (see the changes in BUGS)