refactored some code. changed variable names to have a more coherent naming scheme