Fixed error handling in function last.