Bugfix: prevent index out of bounds exception