refact the code