added basic error handling and logging wrapper