works as a function library; still inefficient