inital commit.
Some more code organization and stylistic changes.