Refactored and fixed bug with file permissions in process