added test case and fixed bugs for procedures