refactor a bit