Correctly registering the listener

The file.exists test is now more reliable.