Added error handling
Removed test code