Refacotr some code