Main logic

Now it's working.
OK. Those codes are just for the functional test. I'll delete them.