refractor a little of my code