cleanup code, improve docs