made output more readable
added some obvious preconditions