More comprehensive fix for #277