Fixed things and cleaned up the code.