Fixed some bug in middle layer.