Common functions and removed Thread.sleep()