error checking now implemented (but not fully tested)