Tidies up the code and makes use of cached container and content sizes.