Modified to use emit().