added isFirst method
fixed isLast method