Adding friend functions, error checking