Fixed file permission problems, cleaned up flow and output