Moved common code to a single file.