added basic error handling and fixed set.table