version 2., somewhat nicer output and cleaner code