Fixed incorrect variable access + reformatted code