refactor how we deal with frames; add a separate library