improve the code of detecting/add/remove bookmark