Changed some stuff in core and cleaned up array access in all of the code