Internal function automatically called when needed.