optimized assigning k variable