fixed bugs in opt-jagr and added tests