Organized the code into something sane