refactor with xpcall
more tests