Implement stat() function