improve library logic