Split external and internal, use defer to make code clear