Moved logic to separate files.