version 2, extract functions