Added check for return value of getcwd()