several improvements to make library more generic