move logic away from main