moving check for last exit code - still does not fix the bug...