Modularizing the code, cleanups, etc.

Signed-off-by: hyakugei <jyule@phantomcompass.com>