Better error handling
Remove all the dead codes