add documentation, cleanup code