Initial refactoring of sproc and function handling.