added assertions and simplified output