bug fixin and tidying