Solution of #11. Lots of duplicated codes. Need to refactor.