Further changes, working up to gradient function