fix accoding to Paul's suggestion. Change the API