hw8: removed unnecessary loops and temp var