refactor a little code