massive cleanup code