bug fixed and tests passed