added some comments and documentation, but still working on it