moved main functionality to function