finished main functionality