Fixed minor errors in stored procedure