proper gateway implementation. add debug define