Re-oragnized code in main deployer

This commit mainly for consolidating duplicated code into method.
In addition, several method are given a better name.