restructuring code, parsing params in stored procedure