cleaned up code, define partial derivatives