Refactor Code according to Karml's review