some cleanup, attempts to be more cache/context friendly