Made some small changes to Cadair's code to fix scaling.