adding tests and refactoring routine waits