Several bugs fixed and enhancements