Added more robust error reporting and better variable usage
Removed unnecessary import and added a TODO