corrected array splice function