fixed some bugs in #2