Avoid duplication, and add logging for some more error conditions so it's possible to see in the logs why a resize has failed or produced unexpected results.