optimises canvas code