added a nil check for code argument