codes refactored