Moved s-function code