[master] Re-factored some logic to separated classes.