Several bugs corrected