Added clever viewport size calculation