cleanup main. removed duplicate code