Updated to fix some bugs