Add agrument error message and some refactoring