inline low-level functions, remove nesting