Corrected some bugs introduced when formatting the code