inlined some functions for modest performance gain