Implements main functions.