Fix duplicated code and rename files