Fixing bug #7 and some minor improvements