Bugs fixed and minor improvement