optimize bgAutoResize method