Fixed some bugs in the older version