minor refactor to handle functions better