Added more input validation and changed argument input order to match the spec, general fixes