need to refine the whole code