Fixed gradient update bugs
merged