Refactoring code.

- Moving core task logic into new Tasks class.