slight refactor to make it more flexible