Modifications for better error handling