massive refactor from svn