Reafctor code and write client