Fixed some errors and formatted code accordingly.