addition of explicit var names and removal of uneeded loops