Major refactor. Created more files to separate concerns.