Added custom Error classes, did some refactoring.