Fixing var name and making small code placement changes for readablity