Fixed some bugs in the previous fix