Add some basic infra functions and some logical codes