refractor some code