fixed bugs #494, #498, #503