Refine implementation. To be debugged.