Implements main functionality.