added verification and error handling
fixed a bug