attempt 2 at preventing nullindexexception