Fixed a bug that made the application crash because index was out of range