Fixed the bugs to make this more readable.