moved main fn around