v5.1 refactor the main module

reduce 1000 to 600 yeah!