wrote main functionality