Optimize port and mem calls