fix bug and add advanced tests