Fix bugs in procedures