Type check
Update error handling
Add debug mode