DRY, move logic to lib, persist nn data if needed