Bugfix: check array before shifting