refactored code, autoresize