fixed invalid case for Array.first
refactored Array.first to use slice to get first n elements