Overhauling more things

Code cleanup, reducing number of exported functions, simplifying, etc