refactor a little not to use pointer