refactor a bit
