refactored main() and added logic processing