move around code and get application and stage to work without threads