import from svn; fix bugs