First version. Must be optimized.