changed the prev and next so that it will accept more elements