style changes
refactor and fix 'middle' bug