Modified move function to accept index as argument and fixed next and prev functionality