Added lockfile function to avoid multiple runs