introduce some state, add scales, cleanup code