error handling, removed some sysouts