Added loop function and make error API