Extract errors to their own file. Add documentation