Modified code to use stored procedures for data acquisition