Updated solution to avoid runtime reflection