Fixed exception handling and updated style