Modified to include function plotting.