Reorganizing code; adding comments and namespaces.