Cleanup

Attempts to make the method update_resource smaller, and the whole code easier to read.