fixed some bugs, using a callback now instead