fixes various bug.