refactor some macro code to helper class