clean up source, add documentation