Added many functions and error handling