Better separation of public vs. private API

Made more functions private and moved them around.