fixed some bugs and slightly changed some function calls