refactored makemiddle to make it simpler