renaming stored procedure and fixing logic