Implemented basic exception handling