code cleanup and changing function parameter name from IP to key