added NULL and error handling to profile