Implemented main functionality