Adding downsampling and improved state machine