some minor variable, class and method changes to make the code clearer.