cleaning up code

threw everything into functions, added docblocks, added an init function. getting ready to set this shit up as RESTful