First pass gradient implementation