Updated stored procedure