improve string handling in main Java class