fix file handling and add shebang to start script