Fixed some bugs in procedures