added better error handling, and arguments