Changed SD filename generation, made SD handling more reliable as a whole (cherry picked from commit 717ec041)