Most of logic implemented.