optimization: lowered retain/release to minimum, passing most objects by const reference, ...
added element count functions, more optimization