refactor code to support proxy