Exception handling. Removed some unused code.