added various error catching, basic functionality seems to be working.