Dynamic resizing now implemented. Solution could be cleaner (use of globals).