bug fixes: some issues remain, need more discussion later