Changed a few things around a little. Symbolic function expressions should work better.