Updated most of the code.