Cleanup

Attempts to make the method update_resource smaller, and the whole code easier to read.
This method is probably better named:
calculate_changes, required_changes or something like that.