moved error messages from main() to subroutines