https://www.togidev.com/how-to-prevent-java-lang-arrayindexoutofboundsexception-in-java/