fixed minor Dream bugs, code reorganization