Fixes error handling and improves error debuging
Removes unused imports