added assertions and some further comments