Removed dead code. Improved error handling