array out of bounds prevention
conversion to lambdas