Hopefully fixed some bugs