Minimal changes, begin error handling
Deleted useless function