Move single instance check logic into one file

Move single instance check logic into a single file.