Several bug fixing