Use API instead of calling external commands
Merge pull request #156 from jgawor/chmod

ty!