refractor some code to methods