my solution with reflection