refactored and wrote reflection