This is mainly copy/paste, so now this almost identical gradient code exists 3 times. That's kinda suboptimal.