Fixed a 'index out of range' error (credit to aluminium)