added better filename handling and CWD