Several bugs fixed and updated documentation