Implemented main functionality.