Some code redesigned.