refactor to functionalize better