Move code for waiting cycle into separate function