Minor update
Improved error handling
Reduced code