minor shuffling of code to clear up the main a bit