Fixed bugs in return function