refine and bugfix