added write permissions, refractored permission code, fixed regex permissions
added write permissions, refractored permission code, fixed regex permissions