More cleanup. More comments. More reusing functions.