resubmitting last commit with a few small things tidied up