code refactor to Foundation