bug fixes, resize handling improvements and refactoring