Split processing function from main code and align code structure