add macro to handle pointer code and refactor for simplicity
add macro to handle pointer code and refactor for simplicity