made minor changes and var renaming