better error and window handling