some even more safe filename handling, and error rescuing