Mostly modified to subtract the initial condition, based on an idea from Adam.