reorganization; fixed minor bugs