Better error handling and path management