merged main code