refactor into a javafx thread method