added resize handling and cursor positioning