How to merge to codes and let them function sequentially