refactored main() for debugging