Start of new function for fitting rect to container