bugfixes to handle arrayoutofbounds exception

Signed-off-by: Arnav Gupta <championswimmer@aokp.co>