Optimize filename generation

Hi,

see here an optimized version of the filename generation at runtime.
(yes I hate strlen and strrchr... ;-)
(includes my previous pull request changes as well)

Matthias