Used mkdir() in place of system() where appropriate