almost finished the code, to be tested in emulator or device.