added more exception and made the class PHP 5.4+