Merged Carlos code