Added Error Throwing. Implemented while loop which needs refactoring.