pull the ja out and refactor the logic