- added some error checking, so that we get more usefull error messages than asserts