added restrict keyword for minor performance improvement