Moved main routine into ScanManifold function