raise if negative detected
move the details down, make the main algorithm easier to read
private things are just implementation details
added test for negative error with a certain message