extract part of programing to function