Made some modifications and bug fixing.