refactor a little bit