fixed some bugs and better API