main logic
main logic