Added ability to use custom errors and added tests